package cn.com.codingce.student.servlet;

import cn.com.codingce.student.entity.Student;
import cn.com.codingce.student.service.IStudentService;
import cn.com.codingce.student.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * Servlet implementation class QueryStudentServlet
 */
@WebServlet("/QueryStudentServlet")
public class QueryStudentServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;


    /*
     * 根据学号查
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int no = Integer.parseInt(request.getParameter("sno"));

        IStudentService service = new StudentServiceImpl();
        Student student = service.queryStudentBySno(no);
        System.out.println(student.toString());

        /*
         * 将查询到的学生放入request域
         */
        request.setAttribute("student", student);

        request.getRequestDispatcher("studentInfo.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request, response);
    }

}
